package com.leyou.item.controller;

import com.leyou.item.service.GoodsHtmlService;
import com.leyou.item.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

@Controller
@RequestMapping("item")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;
    @Autowired
    private GoodsHtmlService goodsHtmlService;

    /**
     * 跳转商品详情页
     * @param id
     * @param model
     * @return
     */
    @GetMapping("{id}.html")
    public String toItemPage(@PathVariable("id") Long id, Model model) {

        long idN = Long.parseLong(String.valueOf(id));
        Map<String, Object> modelMap = goodsService.loadModel(idN);

        model.addAllAttributes(modelMap);
        //页面静态化
        goodsHtmlService.asyncExecute(idN);
        return "item";
    }
}
